package com.nian.global.vo;

import java.io.Serializable;
import java.util.List;

/**
 * 承载返回结果
 *
 * Created by nian on 2021/2/22.
 */
public class QueryResult<T> implements Serializable {

    private int code;
    private String msg;
    private int count;
    private List<T> data;

    public QueryResult() {
    }

    public QueryResult(int count, List<T> dataList) {
        this.count = count;
        this.data = dataList;
    }

    public QueryResult(int code, String msg, int count, List<T> dataList) {
        this.code = code;
        this.msg = msg;
        this.count = count;
        this.data = dataList;
    }

    public QueryResult(int page, int limit, List<T> dataList) {

        int beginIndex = (page - 1) * limit;
        int endIndex = page * limit;
        if (endIndex > dataList.size()) {
            endIndex = dataList.size();
        }
        this.data = dataList.subList(beginIndex, endIndex);
        this.count = dataList.size();
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public List<T> getData() {
        return data;
    }

    public void setData(List<T> data) {
        this.data = data;
    }

}
